package com.sc.outpatientsys.controller;

import com.sc.outpatientsys.entity.Medicine;
import com.sc.outpatientsys.mapper.MedicineMapper;
import com.sc.outpatientsys.service.IMedicineService;
import com.sc.outpatientsys.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/medicine")
public class MedicineController extends BaseController{
    @Autowired
    private IMedicineService medicineService;
    @RequestMapping("/add")
    public JsonResult<Void> addMedicine(Medicine medicine){
        medicineService.add(medicine);
        return new JsonResult<>(OK);
    }
    @RequestMapping("/findByID")
    public JsonResult<Medicine> findByMedicineID(int med_ID){
        Medicine data = medicineService.findById(med_ID);
        return new JsonResult<>(OK,data);
    }
    @RequestMapping("/findByName")
    public JsonResult<Medicine> findByMedicineName(String med_Name){
        Medicine data = medicineService.findByName(med_Name);
        return new JsonResult<>(OK,data);
    }
    @RequestMapping("/findAll")
    public JsonResult<List<Medicine>> findAllMedicine(){
        List<Medicine> data = medicineService.findAll();
        return new JsonResult<>(OK,data);
    }
    @RequestMapping("/findById_List")
    public JsonResult<List<Medicine>> findByID_List(String id_list){
        List<Medicine> data = medicineService.findById_List(id_list);
        return new JsonResult<>(OK,data);
    }


    @RequestMapping("/update")
    public JsonResult<Void> updateMedicine(Medicine medicine){
        medicineService.update(medicine);
        return new JsonResult<>(OK);
    }

    @RequestMapping("/delete")
    public JsonResult<Void> deleteMedicine(int med_ID){
        medicineService.delete(med_ID);
        return new JsonResult<>(OK);
    }
}
